<?php
namespace Home\Controller;
use Think\Controller;
class ClubController extends Controller {
 //  public function picturelist(){
  //      $pictureModel=M('picture');
  //      $data=$pictureModel->order('uid desc')->select();
  //      echo json_encode($data);
  //  }
  //  public function picturelist(){//当前用户所有晒图信息
 //     $id=$_GET['uid'];
  //      $pictureModel=M('picture');
 //       $data=$pictureModel->where("uid='$id'")->select();
 //       $this->assign('picturelist',$data);
 //       $this->display();
  //  }

    public function clublist(){
        $clubModel=M('club');
        $data=$clubModel->order('clubid')->select();
       $this->assign('clublist',$data);
       $this->display();
    }
   // public function picturedetail(){
    //    $id["pid"]=I('get.pid');
   //     $data=M("picture")->where($id)->find();
   //     echo json_encode($data);
   // }
    public function clubdetail(){//晒图详情
      $id=$_GET['clubid'];
        $clubModel=M('club');
       // $data=$pictureModel->where("pid='$id'")->find();
       // $this->assign('picdetail',$data);
     $data=$clubModel->where("clubid=$id")->find();
    //   $this->picturedetail=$data;
         $this->assign('clubdetail',$data);
        //var_dump($data);

        $this->display();

    }
    public function editclub($clubid)
    {
       
    $clubModel=M('club');
    $data=$clubModel->where("clubid=$clubid")->find();
    $this->clubdetail=$data;
    $this->display();
    //var_dump($data);
    // echo json_encode($one);
   }
   // public function updatepicture(){
   //  $data=$_POST;
   //  $file=$_FILES;
   //  $pictureModel=M('picture');
   //  if($picturemodel->create()){
   //      if ($picturemodel->save()) {
   //          $this->success('修改成功','picturelist');
   //      }else{
   //          $this->error('修改失败');
   //      }
   //  }

   //  }
public function updateclub(){

            $data=$_POST;
            $file=$_FILES;
            $clubid=$data['clubid'];
            //dump($data);
            
                    
            $clubModel = M('club'); // 实例化User模型
            // 要修改的数据对象属性赋值
            //$userModel->create();   // 根据表单提交的POST数据创建数据对象
            //dump($data);
        //$result=$userModel->where("id=$id")->save($data);

        if($file['clubpic']['size']==0) {
            //没有修改头像
            $result=$clubModel->where("clubid=$clubid")->save($data);
  
        }else{
            //修改头像
            $upload = new \Think\Upload();// 实例化上传类
            $upload->maxSize  = 3145728 ;// 设置附件上传大小
            $upload->allowExts  = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
            $upload->rootPath  =  './';
            $upload->savePath =  'Public/Uploads/picture/';// 设置附件上传目录
            $upload->autoSub = false;
            $upload->saveName = date("YmdHis").rand(100,999);//定义名字
            $info = $upload->upload();
    
            if(!$info) {// 上传错误提示错误信息
                    $this->error($upload->getError());
             }else{// 上传成功 获取上传文件信息
                 //保存表单数据 包括附件数据
                $data['clubpic']= $info['clubpic']['savename']; 
                $result=$clubModel->where("clubid=$clubid")->save($data);
                    if ($data['oldpic']!='nopic.jpg') {
                    $oldpicPath='Public/Uploads/picture/'.$data['oldpic'];
                    unlink($oldpicPath);
                        }
                    }
            }

        if($result){
             $this->success('修改成功！','clublist');
             }
            else{
                $this->error('修改失败！');
                }
    }
public function delclub( )
    {

       // $id=I('id');
        $id=$_GET['clubid'];
        $clubModel = M('club');//实例化news对象
        if($clubModel->delete($id)) {
            $this->success('删除成功');
            //echo json_encode('1');
        }
        else {
           $this->error('删除失败');
          
            //echo json_encode('0');
        }
    }
 

    





  
}